package com.ht.api.config;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.redisson.config.SingleServerConfig;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

@Configuration
@Component
public class RedissonConfig {
	@Value("${spring.data.redis.ip}")
	private String ip;
	@Value("${spring.data.redis.port}")
	private int port;
	@Value("${spring.data.redis.password}")
	private String pwd;

	@Bean
	public RedissonClient redissonClient() {
		Config config = new Config();
		SingleServerConfig ssc = config.useSingleServer().setAddress("redis://" + ip + ":" + port);
		if (pwd != null && !pwd.isEmpty()) {
			ssc.setPassword(pwd);
		}
		RedissonClient redisson = Redisson.create(config);
		return redisson;
	}
}
